package cn.zhl.leetcode.链表;

/**
 * @program: demos
 * @description: https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list/
 * @author: 刘振华
 * @create: 2020-04-03 11:26
 **/
public class _83_删除排序链表中的重复元素 {
	//    给定一个排序链表，删除所有重复的元素，使得每个元素只出现一次。
//    示例 1:
//    输入: 1->1->2
//    输出: 1->2
//    示例 2:
//    输入: 1->1->2->3->3
//    输出: 1->2->3
	public static ListNode deleteDuplicates(ListNode head) {
		if (head == null) {
			return head;
		}
		ListNode node = head;
		while (node.next != null) {
			if (node.val == node.next.val) {
				node.next = node.next.next;
			} else {
				node = node.next;
			}
		}
		return head;
	}

	public static void main(String[] args) {
		int[] ints = {1, 1, 1, 1, 1, 1, 1};
//        int[] ints = {1,1,2,2,3,3,4,4,4,4,4,4,5,5,5,5,5,5};
		ListNode node = ListNode.head(ints);


		node = deleteDuplicates(node);

		while (node != null) {
			System.out.println(node.val);
			node = node.next;
		}

	}
}
